package com.rocky.study.volatitle;

class Test {
//    volatile int number = 0;
    int number = 0;

    void methodExchange() {
//        number = 100;
        this.number = 100;
    }
}

public class VolatitleDemo1 {
    public static void main(String[] args) {
//        extracted();
        Test myDate = new Test();
        Thread thread = new Thread(){
            @Override
            public void run() {
                System.out.println("---->come in");
                myDate.methodExchange();
            }
        };
        thread.start();
        while (myDate.number == 0) {
            System.out.println("====volatile保证可见性验证代码===");
        }
        System.out.println("---->game over" + "<----number = "+ myDate.number);
    }

    private static void extracted() {
        Test myDate = new Test();
        myDate.methodExchange();
        System.out.println(myDate.number);
    }
}
